"""
@file Intermediate.py
@author GalaktiK (jacobliu001@qq.com)
@version 1.0
@date 2020-12-25

@copyright Copyright (c) 2020, Published under License GPLv2
"""
def getOctRepr(x: int) -> str:
    return "%o"%(x)

def getSumDig(x: int) -> int:
    return sum(map(int, getOctRepr(x)))

for TC in range(5):
    s, d, r = input().split()
    st = int(s, 8)
    dif = int(d, 8)
    n = int(r)
    acc = 0
    for p in range(n*(n-1)//2, n*(n+1)//2):
        acc += getSumDig(st + p * dif)
    print("%d. %s"%(TC+1,acc))
